#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef pair < int , int > pii;
typedef vector < int > vec;
typedef vector < pii > veg;
typedef long long ll;
typedef double db;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch =='-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

int n,m;
ll ans;

inline ll C3(int x) { return 1ll * x * (x - 1) * (x - 2) / 6; }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in + 1,m = in + 1; ans = C3(n * m);
    ans -= 1ll * n * C3(m); ans -= 1ll * m * C3(n);
    for(int i = 1;i < n;i++) for(int j = 1;j < m;j++) ans -= 2ll * (__gcd(i,j) - 1) * (n - i) * (m - j);
    printf("%lld\n",ans);
    return 0;
}
